#include <Python.h>

#include "bloom.h"


/*$Id: bloomext.c 5 2012-10-26 04:17:18Z hymm91@gmail.com $*/

static struct bloom_context _g_ctx;

static PyObject *starts(PyObject *self, PyObject *args);

static PyObject *finish(PyObject *self, PyObject *args);

static PyObject *isexist(PyObject *self, PyObject *args);

static PyObject *starts(PyObject *self, PyObject *args)
{
	const char *file;
	ssize_t size;
	int init;

	if (!PyArg_ParseTuple(args, "s|i|i", &file, &init, &size)) {
		return NULL;
	}

	int err;
	err = bloom_starts(file, init, size, &_g_ctx);

	return Py_BuildValue("i", err);
}

static PyObject *isexist(PyObject *self, PyObject *args)
{
	const char *str;
	int len;
	if (!PyArg_ParseTuple(args, "s|i", &str, &len)) {
		return NULL;
	}
	int exist;	
	exist = bloom_isexist(str, len, &_g_ctx);
	return Py_BuildValue("i", exist);

}

static PyObject *finish(PyObject *self, PyObject *args) 
{
	int err;
	err = bloom_finish(&_g_ctx);
	return Py_BuildValue("i", err);
}
static PyMethodDef addMethods[] = 
{
	{"starts", starts, METH_VARARGS, "bloom init"},
	{"finish", finish, METH_VARARGS, "bloom finish"},
	{"isexist", isexist, METH_VARARGS, "bloom isexist"},
	{NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC initbloomext()
{
	Py_InitModule("bloomext", addMethods);
}

/*$Id: bloomext.c 5 2012-10-26 04:17:18Z hymm91@gmail.com $*/
